﻿@using Lapkin.Models.DataModels
@model IEnumerable<Category>

<ul>
    @foreach (Category category in Model.Where(c => c.Parent == null))
    {
        <li data-alias="@category.Alias" data-id="@category.Id" id="tree_@category.Id">
            <a href="#">@category.Name</a>
            @RenderMenuItem(category)
        </li>
    }
</ul>

@helper RenderMenuItem(Category parentItem){
    var categories = Model.Where(c => c.Parent != null && c.Parent.Id == parentItem.Id);
    if (categories.Any())
    {
        <ul>
            @foreach (Category category in Model.Where(c => c.Parent != null && c.Parent.Id == parentItem.Id))
            {
                <li data-alias="@category.Alias" data-id="@category.Id" id="tree_@category.Id">
                    <a href="#">@category.Name</a>
                    @RenderMenuItem(category)
                </li>
            }
        </ul>
    }
}